How to use the <a> Tag In HTML
Using the <a>
tag, you can turn an HTML element into a link by wrapping it with an anchor tag and setting the href
attribute to the desired URL.
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > < title >Div as Link</ title > </ head > < body > < h1 >w3wiki</ h1 > </ a > </ body > </ html > |
Output:
How to Convert a Div into a Link in HTML ?
To transform a <div>
into a link, use the we can use anchor
tag by wrapping the <div>
with it. Set the href
attribute of the anchor tag to the desired URL or target location. In this example we will see multiple approaches to do so:
Table of Content
- Using the Tag
- Using JavaScript event handling